import './style.less';

const toastInfo={
    dom:null,
    timer:null, //定时器
}
export function showToast(opts) {
    const title= opts.title || '';
    const duration= opts.duration || 1500;
    const icon= opts.icon || 'success';
    if(!title) return;


    if(toastInfo.dom) {
        clearTimeout(toastInfo.timer);
        // toastInfo.dom.removeChild(toastInfo.dom);
        toastInfo.dom.remove();
        toastInfo.dom=null;
    }

    toastInfo.dom=document.createElement('div');
    toastInfo.dom.classList.add('ui-toast', `ui-toast-${icon}`);
    toastInfo.dom.innerText=`<p>${title}</p>`
    document.body.appendChild(toastInfo.dom);
    toastInfo.timer=setTimeout(()=>{
        toastInfo.dom.remove();
        toastInfo.dom=null;
    },duration)
}